package com.youcash.ZyWallet_spring.controller;

import com.youcash.ZyWallet_spring.entity.LoansType;
import com.youcash.ZyWallet_spring.service.LoansTypeService;

import com.youcash.ZyWallet_spring.vo.ResultVO;

import io.swagger.annotations.Api;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Zhangzifeng
 */
@RestController
@RequestMapping("/loans")
@CrossOrigin
@Api(value = "提供贷款类型的添加、修改、删除、查询的相关接口", tags = "贷款类型管理")//类注解：可以对控制器类进行详细说明
public class LoansTypeController {

    @Autowired
    private LoansTypeService loansTypeService;
    
    @GetMapping("/get")
    @ApiOperation("获取全部贷款列表的接口")
    public ResultVO listLoans() {
        return loansTypeService.listLoans();
    }

    @GetMapping("/get/{status}")
    @ApiOperation("通过状态值获取贷款列表的接口")
    @ApiImplicitParam(dataType = "Integer", name = "status", value = "贷款产品的状态", required = true)
    public ResultVO listLoansByStatus(@PathVariable("status") Integer status) {
        return loansTypeService.listLoansByStatus(status);
    }

    @PutMapping("/updateStatus/{id}/{status}")
    @ApiOperation("通过id更新状态值")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "Integer", name = "id", value = "贷款产品的id", required = true),
            @ApiImplicitParam(
                    dataType = "Integer", name = "status", value = "状态", required = true)
    })
    public ResultVO updateStatusById(@PathVariable("id") Integer id,
                                     @PathVariable("status") Integer status) {
        return loansTypeService.updateStatus(id, status);
    }

    @PostMapping("/add")
    @ApiOperation("增加贷款产品的接口")
    public ResultVO addLoans(@RequestBody LoansType loansType) {
        return loansTypeService.addLoans(loansType);
    }

    @ApiOperation("用于修改贷款的接口")
    @PutMapping("/updateInfo/{id}")
    @ApiImplicitParams({
            //方法注解：说明接口方法的参数
            @ApiImplicitParam(
                    dataType = "string", name = "loans", value = "产品名称", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "deadline", value = "有效期限", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "quota", value = "额度", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "apr", value = "年利率", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "description", value = "描述", required = false),
            @ApiImplicitParam(
                    dataType = "string", name = "introduction", value = "介绍", required = false)
    })
    public ResultVO updateInfo(@PathVariable("id") Integer id,
                               String loans,
                               String deadline,
                               String quota,
                               String apr,
                               String description,
                               String introduction,
                               String updatetime) {
        return loansTypeService.updateInfo(id, loans, deadline, quota, apr, description, introduction, updatetime);
    }
}
